#!/usr/bin/env dash
# eval things, handle special cases.

# the prefix used to signal upper panel:
prefix=meta

case "$*" in
  mouse_middle*|scroll_down*|mouse_right*|mouse_left*|scroll_up*)
    event="$1"
    shift
    action="$@"

    echo "${prefix}${juicedLemon}_${event}='${action}'"
    echo "${prefix}generate_mouse_events ${juicedLemon} ${event}"
    ;;
  invert)
    eval echo ${prefix}${juicedLemon}_bg="\$${juicedLemon}_fg"
    eval echo ${prefix}${juicedLemon}_fg="\$${juicedLemon}_bg"
    ;;
  active)
    eval echo ${prefix}${juicedLemon}_bg="\$${juicedLemon}_activebg"
    eval echo ${prefix}${juicedLemon}_fg="\$${juicedLemon}_activefg"

    result="%{"
    for section in activeunderline activeoverline; do
        if [ "$(eval "echo \${${juicedLemon}_${section}}")" = "true" ]; then
            [ "$section" = "activeunderline" ] && postfix="u" || postfix="o"
            result="${result}+${postfix}"
        fi
    done
    result="${result}U$(eval "echo \${${juicedLemon}_activeline}")}"
    echo "${prefix}line[\"${juicedLemon}\"]=\"$result\""
    ;;
  reset)
    eval echo ${prefix}${juicedLemon}_bg="\$${juicedLemon}_bg"
    eval echo ${prefix}${juicedLemon}_fg="\$${juicedLemon}_fg"

    result="%{"
    for section in underline overline; do
        if [ "$(eval "echo \${${juicedLemon}_${section}}")" = "true" ]; then
            result="${result}+$(echo $section | cut -c1)"
        fi
    done
    result="${result}U$(eval "echo \${${juicedLemon}_line}")}"
    echo "${prefix}line[\"${juicedLemon}\"]=\"$result\""
    ;;
  start)
    echo ${prefix}hold=true
    ;;
  end)
    echo ${prefix}hold=false
    ;;
  # pad)
  #   printf "%s" "%{O$1}"
    # ;;
  set*)
    # assume "set <content>", eg "set fg=#ffffff"
    shift
    echo "${prefix}${juicedLemon}_$*"
    ;;
  *)
    echo "${prefix}$*"
    ;;
esac
